package Stack;

import Array.Array;

public class ArrayStack<E> implements Stack<E> {

    Array<E> array;

    public ArrayStack(int capacity) {
        this.array = new Array<E>(capacity);
    }

    public ArrayStack() {
        this.array = new Array<E>();
    }

    public int size() {
        return array.getSize();
    }


    public boolean isEmpty() {
        return array.isEmpty();
    }

    public int getCapacity() {
        return array.getCapacity();
    }

    public void push(E e) {
        array.addLast(e);
    }

    public E peek() {
        return array.getLast();
    }

    public E pop() {
        return array.removeLast();
    }


    @Override
    public String  toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(String.format("Stack : "));
        builder.append(" [ ");
        for (int i = 0; i < array.getSize(); i++) {
            builder.append(array.get(i));
            if (i != array.getSize() - 1) {
                builder.append(",");
            }
        }
        builder.append(" ]  top ");
        return builder.toString();
    }
}
